'use strict';
const db = uniCloud.database()
exports.main = async (event, context) => {
	
	const res_clinic_id = await db.collection('rx-users-clinic').doc(event._id).get()
	
	let list1 = res_clinic_id.data[0].clinic 
	let list2 = event.refer_clinic_id // 医生诊所ID
	let list3 = event.clinic_id_list // 用户可以操作的列表 
	
	const newElements = list1.filter(item => !list2.includes(item)) || [];
	const new_list = [...newElements, ...list3]
	
	await db.collection('rx-users-clinic').doc(event._id).update({clinic: new_list})
	
	//返回数据给客户端
	return { data: new_list, code: 200, msg: 'ok.' }
};
